from django.db import models
from users.models import BaseModel
# Create your models here.


# 学习资料表
class LearningMaterialsModel(BaseModel):
    name = models.CharField(max_length=50, verbose_name="资料名称")
    user_id = models.BigIntegerField(verbose_name="发布人id")
    price = models.DecimalField(max_digits=5, decimal_places=2, verbose_name='价格')
    desc = models.CharField(max_length=100, verbose_name="简介", default="暂无简介", null=True, blank=True)
    count = models.IntegerField(verbose_name="学习次数", default=0)
    image = models.CharField(max_length=256, verbose_name="图片", default="", null=True, blank=True)
    study_id = models.BigIntegerField(verbose_name="学习内容id", default=None)

    class Meta:
        db_table = "learning_materials_tb"
        verbose_name = "学习资料表"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


# 分类表
class ClassModel(BaseModel):
    name = models.CharField(max_length=30, verbose_name="分类名称")
    school_id = models.BigIntegerField(verbose_name="所属学校", null=True, blank=True, default=None)

    class Meta:
        db_table = "class_tb"
        verbose_name = "分类表"
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.name


# 学习资料目录表
class CatalogueModel(BaseModel):
    name = models.CharField(max_length=30, verbose_name="目录名称")
    cid = models.ForeignKey('self', related_name="cata", on_delete=models.CASCADE, null=True, blank=True)
    desc = models.CharField(max_length=50, verbose_name='简介', default="", null=True, blank=True)
    data_id = models.BigIntegerField(verbose_name="所属资料")

    class Meta:
        db_table = "catalogue_tb"
        verbose_name = "学习资料目录表"
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.name


# 学习内容表
class StudyContentModel(BaseModel):
    title = models.CharField(max_length=30, verbose_name="标题")
    content = models.CharField(max_length=256, verbose_name='内容')
    desc = models.CharField(max_length=50, verbose_name="简介", null=True, blank=True)
    class_id = models.BigIntegerField(verbose_name="所属分类id")
    # 1否， 0是
    is_overt = models.BooleanField(default=False, verbose_name="是否公开")
    label = models.CharField(max_length=50, verbose_name="标签", null=True, blank=True)
    label_id = models.BigIntegerField(verbose_name="标签id", null=True, blank=True)
    user_id = models.BigIntegerField(verbose_name="发起人id")
    # 0已分享   1未分享
    is_share = models.BooleanField(default=True, verbose_name="是否分享")

    class Meta:
        db_table = 'study_content_tb'
        verbose_name = '学习内容表'
        verbose_name_plural = verbose_name
    def __str__(self):
        return f"发起人{self.user_id}, 标题：{self.title}"


# 标签表
class LabelModel(BaseModel):
    name = models.CharField(max_length=30, verbose_name="标签名")

    class Meta:
        db_table = "label_tb"
        verbose_name = '标签表'
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.name


# 学习任务
class StudyTaskModel(BaseModel):
    user_id = models.BigIntegerField(verbose_name="发起人id")
    grade_id = models.BigIntegerField(verbose_name="班级id")
    study_content_id = models.BigIntegerField(verbose_name="学习内容id")

    class Meta:
        db_table = "study_task_tb"
        verbose_name = "学习任务表"
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.user_id


# 学习记录
class StudyRecordModel(BaseModel):
    user_id = models.BigIntegerField(verbose_name="所属用户id")
    stu_task_id = models.BigIntegerField("所属任务id")
    duration = models.DateTimeField(verbose_name="学习时长")


    class Meta:
        db_table = "study_record_tb"
        verbose_name = "学习记录表"
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.user_id


# 搜索记录表
class SearchHistoryModel(BaseModel):
    user_id = models.BigIntegerField(verbose_name="所属用户id")
    content = models.CharField(max_length=50, verbose_name="搜索内容")
    class Meta:
        db_table = 'search_history_tb'
        verbose_name = '搜索记录表'
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.user_id


# 评论表
class CommentModel(BaseModel):
    user_id = models.BigIntegerField(verbose_name="评论人id")
    study_content_id = models.BigIntegerField(verbose_name="学习内容id")
    content = models.CharField(max_length=50, verbose_name="评论内容")

    class Meta:
        db_table = "comment_tb"
        verbose_name = "评论表"
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.user_id


# 收藏表
class CollectModel(BaseModel):
    user_id = models.BigIntegerField(verbose_name="收藏人id")
    study_content_id = models.BigIntegerField(verbose_name="学习内容id")

    class Meta:
        db_table = "collect_tb"
        verbose_name = "收藏表"
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.user_id


# 点赞表
class LikeModel(BaseModel):
    user_id = models.BigIntegerField(verbose_name="点赞人id")
    study_content_id = models.BigIntegerField(verbose_name="学习内容id")

    class Meta:
        db_table = "like_tb"
        verbose_name = "点赞表"
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.user_id


# 订单表
class OrderModel(BaseModel):
    PAY_STATUS = (
        (1, '待支付'),
        (2, '待发货'),
        (3, '待收货'),
        (4, '待评价'),
        (5, '已完成'),
        (6, '已超时')
    )
    order_id = models.CharField("订单id", max_length=200, default="")
    user_id = models.BigIntegerField(verbose_name='顾客id')
    data_id = models.BigIntegerField(verbose_name="资料id")
    school_id = models.BigIntegerField(verbose_name="所属学校id")
    status = models.SmallIntegerField(default=1, choices=PAY_STATUS, verbose_name="订单状态")
    price = models.DecimalField(max_digits=7,decimal_places=2, default=0 ,verbose_name="总价")
    order_num = models.IntegerField("商品数量", default=0)
    # 0为否  1为是
    is_refund = models.IntegerField("是否退款", default=0)

    def __str__(self):
        return "订单%s"%self.order_id

    class Meta:
        db_table = 'order_tb'
        verbose_name_plural = '订单表'
